﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Xls;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Xml.Serialization;
using System.Data;
using System.Data.OleDb;

namespace workshop3
{
    public static class ClassExcelToXml
    {
        public static void ExcelToXml(string path,string name)
        {
            String Path = path;
            string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Path + ";" + "Extended Properties='Excel 12.0;HDR=YES;IMEX=1'";
            OleDbConnection conn = new OleDbConnection(strConn);//build up the connection to the excel file
            conn.Open();
            string strExcel = "";
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            strExcel = "select * from [工作表1$]";//select the sheet 1 in the excel file
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            ds = new DataSet("Students");
            myCommand.Fill(ds, "student");//set the node name
            //ClassCreateXML.CreateXmlFile(name);
            ds.WriteXml(name+".xml");//write the data into xml
        }
     }
}
